$(function () {

    var result = true;
    //新增
    $("[name='btn_save_new_depot']").click(function () {

        var form = window.form_new_depot;
        var name = form.name.value;
        var address = form.address.value;
        var sta = form.sta.value;
        // var nodes = "";
        // $('input[name="nodes"]:checked').each(function(){
        //     nodes += $(this).val()+",";
        // })
        var lgsDepot = {name: name, address: address,sta: sta };
        if(result){
            // result= false;
            $.postJsonBody("/lgsDepot/postLgsDepot", lgsDepot, function (re) {
                window.location.href=window.location.href;
                window.location.reload;
            })
            // result = true;
        }

    });

    //编辑
    $("[name='btn_save_edit_depot']").click(function () {
        var form = window.form_edit_depot;
        var id = form.id.value;
        var name = form.name.value;
        var address = form.address.value;
        var sta = form.sta.value;
        // var nodes = "";
        // $('input[name="editNodes"]:checked').each(function(){
        //     nodes += $(this).val()+",";
        // })
        var depot = {id:id,name: name, address: address, sta: sta };
        $.postJsonBody("/lgsDepot/update" , depot, function (re) {

            window.location.href=window.location.href;
            window.location.reload;
        })
    });

    // 编辑详情
    $('#md_edit_depot').on('show.bs.modal', function (event) {
        var _e = $(event.relatedTarget);
        var id = _e.data("depot-id");
        var modal = $(this);
        var form = window.form_edit_depot;
        $.get("/lgsDepot/getLgsDepot/" + id, function (re) {
            var depot = re.data.lgsDepot;
            // var nodeList = re.data.nodeList;
            form.id.value = depot.id;
            form.name.value = depot.name;
            form.address.value = depot.address;
           //  $("[name='nodes']").prop("checked", false);
           // for(var i=0;i<nodeList.length;i++){
           //     $(".nodes_"+nodeList[i].nodeId).prop("checked", true);
           // }
            form.sta.value = depot.sta;


        });
    });
})